clear all; close all; clc;
R = 220;
C = 33e-9;
L = 100e-6;
Ce = C/2;

W = 1/(R*Ce);
F = W/(2*pi);

%fprintf('f = %F MHz\n', F/1e6); 

T = 1/(10000*F)
t = 0:T:(15 * 1/F); 
lt = length(t);

Uc = nan(1,lt);
UR = nan(1,lt);
I = nan(1,lt);
dI = nan(1,lt);


f=F;
A=[0; 1; 2; 3];
U = nan(length(A),lt);
for n = 1:length(A)
    E = A(n)*cos(2*pi*f*t);
    





Uc(1)=0;
I(1)=0;
dI(1)=I(1)/Ce;
UR(1)=0;

    for k =2:lt
    UR(k) = E(k-1)-Uc(k-1);
    I(k)=UR(k)/R-(UR(k)/(R*C))*T;
    Uc(k) = E(k-1) - I(k)*R;
    end
U(n,:)=Uc/2;
end
figure(1);

plot(t*1e9, [E; U]); 

xlabel('t,ns')
ylabel('U_c, E,U,Volt')
legend('E(t|A=3)', 'U(t|A=0)', 'U(t|A=1)', 'U(t|A=2)', 'U(t|A=3)') 
grid on
    
